/**
 * echarts图表配置文件
 */
const echarts = require('echarts')
// echarts动画完成时间
const animationDuration = 4000
export default (datalist, seriesData, liquidfillData = { value: 0, allValue: 0, title: '', color: [] }) => ({
  // 水波球配置对象
  liquidfillOp: {
    // backgroundColor: "#050038",
    title: {
      text: `${liquidfillData.value}`,
      left: "center",
      top: "40",
      textStyle: {
        fontWeight: "normal",
        fontSize: 30,
        color: "rgb(255,255,255)"
      },
      subtext: `${liquidfillData.title}`, //副标题
      subtextStyle: {
        fontWeight: "bold",
        fontSize: 12,
        color: "#0f0044"
      }
    },

    series: [
      {
        type: "liquidFill", // 图表类型
        radius: "70%",
        center: ["50%", "50%"],
        data: [
          liquidfillData.value / liquidfillData.allValue,
          liquidfillData.value / liquidfillData.allValue,
          liquidfillData.value / liquidfillData.allValue
        ], // data个数代表波浪数
        backgroundStyle: {
          borderWidth: 1,
          color: "#0f0044"
        },
        label: {
          normal: {
            show: false, //不显示label  用副标题代替了
            formatter: (0.5 * 100).toFixed(0) + "%",
            textStyle: {
              fontSize: 16,
              color: "black"
            }
          }
        },
        color: [  //color一定要是个数组 ，每一项对应一个波浪，可以给每个波浪单独配置颜色
          {
            type: "linear",
            x: 0,
            y: 0,
            x2: 0,
            y2: 1,
            colorStops: [
              {
                offset: 1,
                // color: "#283b54"
                color: liquidfillData.color[0]
              },
              {
                offset: 0,
                // color: "#283b54"
                color: liquidfillData.color[0]
              }
            ],
            globalCoord: false
          },
          {
            type: "linear",
            x: 0,
            y: 0,
            x2: 0,
            y2: 1,
            colorStops: [
              {
                offset: 1,
                // color: "#2e4996"
                color: liquidfillData.color[1]
              },
              {
                offset: 0,
                // color: "#2e4996"
                color: liquidfillData.color[1]
              }
            ],
            globalCoord: false
          },
          {
            type: "linear",
            x: 0,
            y: 0,
            x2: 0,
            y2: 1,
            colorStops: [
              {
                offset: 1,
                // color: "#487bec"
                color: liquidfillData.color[2]
              },
              {
                offset: 0,
                // color: "#487bec"
                color: liquidfillData.color[2]
              }
            ],
            globalCoord: false
          }
        ],
        outline: {
          show: false
        }
      },
      //外层线
      {
        type: "pie",
        center: ["50%", "50%"],
        radius: ["91%", "93%"], //外层线粗细
        hoverAnimation: false,
        data: [
          {
            name: "",
            value: liquidfillData.allValue,
            labelLine: {
              show: false
            },
            itemStyle: {
              color: "#67CDFB"
            },
            emphasis: {
              labelLine: {
                show: false
              },
              itemStyle: {
                // color: "#5886f0"
              }
            }
          }
        ]
      },
      //进度线
      {
        type: "pie",
        center: ["50%", "50%"],
        radius: ["90%", "95%"], //进度线粗细
        hoverAnimation: false,
        data: [
          {
            name: "",
            value: liquidfillData.value, //进度
            labelLine: {
              show: false
            },
            itemStyle: {
              color: {
                type: "linear",
                x: 0,
                y: 0,
                x2: 1,
                y2: 2,
                colorStops: [
                  // !! 在此添加渐变过程色 !!
                  // { offset: 0, color: "#33E2ED" },
                  // { offset: 1, color: "#807AFE" }
                  { offset: 0, color: liquidfillData.color[2] },
                  { offset: 1, color: liquidfillData.color[2] }
                ]
              }
            },
            emphasis: {
              labelLine: {
                show: false
              },
              itemStyle: {
                // color: "#5886f0"
              }
            }
          },
          {
            //画剩余的刻度圆环
            name: "",
            value: liquidfillData.allValue - liquidfillData.value,
            itemStyle: {
              // color: "rgba(0,0,0,0)"
              color: liquidfillData.color[2]
            },
            label: {
              show: false
            },
            labelLine: {
              show: false
            },
            emphasis: {
              labelLine: {
                show: false
              },
              itemStyle: {
                // color: "#050038"
                color: liquidfillData.color[2]
              }
            }
          }
        ]
      }
    ]
  },
  // 党员活动平均参与率配置对象
  participationRate: {
    series: [{
      type: 'gauge', // 类型
      startAngle: 180, // 仪表盘起始角度
      endAngle: 0, // 仪表盘结束角度
      min: 0, // 仪表盘最小值
      max: 100, // 仪表盘最大值
      splitNumber: 12, // 仪表盘刻度的分割段数
      radius: '130%',
      center: ['50%', '80%'],
      itemStyle: {
        color: new echarts.graphic.LinearGradient(1, 0, 0, 0, [{ // 设置颜色为线性渐变
          offset: 0,
          color: '#F5A72B' // 0% 处的颜色
        }, {
          offset: 1,
          color: '#00E4FF' // 100% 处的颜色
        }], false)
      },
      progress: {
        show: true,
        roundCap: true,
        width: 12
      },
      pointer: {
        show: false
      },
      axisLine: {
        roundCap: true,
        lineStyle: {
          width: 12,
          color: [[1, '#585959']]
        }
      },
      axisTick: {
        show: false
      },
      splitLine: {
        show: false
      },
      axisLabel: {
        show: false
      },
      title: {
        show: false
      },
      detail: {
        show: true,
        offsetCenter: [0, '-10%'],
        borderRadius: 8,
        formatter: function (value) {
          return '{value|' + value.toFixed(0) + '%' + '}'
        },
        rich: {
          value: {
            color: '#00E4FF',
            fontSize: '31px'
          }
        }
      },
      data: [{
        value: datalist
      }]
    }]
  },
  // 党员分布情况配置对象
  educationOption: {
    title: {
      text: ''
    },
    credits: {
      enabled: false
    },
    chart: {
      type: 'pie', // 饼图
      options3d: {
        enabled: true, // 使用3d功能
        alpha: 45, // 延y轴向内的倾斜角度
        beta: 0
      },
      backgroundColor: null,
      marginTop: -220
    },
    plotOptions: {
      pie: {
        size: 100,
        allowPointSelect: true, // 每个扇块能否选中
        cursor: 'pointer', // 鼠标指针
        depth: 25, // 饼图的厚度
        dataLabels: {
          softConnector: false,
          overflow: 'crop',
          useHTML: true,
          distance: 20,
          enabled: true, // 是否显示饼图的线形tip
          align: 'left',
          formatter: function () {
            var percent = 0
            percent = this.percentage.toFixed(0)
            return '<div style="width: 63px !important; display:inline-block; white-space:pre-wrap !important;">' + this.point.name + percent + '%' + '</div>'
          },
          style: {
            fontSize: '12px',
            fontWeight: '400',
            textOutline: 'none',
            color: '#fff',
            marginTop: -135
          }
        }
      }
    },
    series: [{
      type: 'pie',
      // size: '80%',
      startAngle: 180,
      name: '数量', // 统一的前置词,非必须
      data: datalist
    }]
  },
  // 集体经济配置对象
  developmentIndex: {
    title: {
      text: '单位：万元',
      left: '1%',
      top: '0%',
      textStyle: {
        color: '#fff',
        fontSize: 14,
        align: 'center'
      }
    },
    xAxis: {
      type: 'category',
      data: datalist && datalist.length > 0 ? datalist[0] : [],
      axisTick: {
        show: false
      },
      axisLine: {
        show: false,
        lineStyle: {
          color: '#FFFFFF'
        },
        symbol: ['none', 'arrow']
      },
      axisLabel: {
        margin: 10,
        color: '#fff',
        textStyle: {
          fontSize: 16
        }
      }
    },
    yAxis: {
      type: 'value',
      axisLabel: {
        show: false,
      },
      axisLine: {
        show: false
      },
      splitLine: {
        show: false
      }
    },
    grid: {
      bottom: '25%',
      left: '0%',
      right: '0%'
    },
    legend: {
      left: 120,
      bottom: 0,
      data: ['经营性收入', '经常性收入', '全区平均'],
      textStyle: {
        color: '#fff',
        fontSize: 13
      },
      selectedMode: false
    },
    series: [{
      name: '经营性收入',
      data: datalist && datalist.length > 0 ? datalist[1] : [],
      type: 'bar',
      barWidth: 20,
      barGap: '180%',
      animationDuration: animationDuration,
      animationEasing: 'cubicInOut',
      itemStyle: {
        normal: {
          label: {
            show: true,
            position: 'top',
            textStyle: {
              color: '#fff',
              fontSize: 14
            }
          },
          borderWidth: 1,
          barBorderRadius: [18, 18, 9, 9],
          color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
            offset: 0,
            color: '#14797B' // 0% 处的颜色
          }, {
            offset: 1,
            color: '#24B2B1' // 100% 处的颜色
          }], false)
        }
      }
    }, {
      name: '经营性收入',
      type: 'pictorialBar',
      z: 3,
      itemStyle: {
        color: '#29B6B6'
      },
      symbol: 'circle',
      symbolSize: ['20', '10'],
      symbolPosition: 'start',
      symbolOffset: [-84, 0],
      data: datalist && datalist.length > 0 ? datalist[1] : []
    },
    // {
    //   name: '经营性收入',
    //   type: 'pictorialBar',
    //   z: 3,
    //   itemStyle: {
    //     color: '#29B6B6'
    //   },
    //   symbol: 'circle',
    //   symbolSize: ['20', '10'],
    //   symbolPosition: 'end',
    //   symbolOffset: [-84, 0],
    //   animationDuration: animationDuration2,
    //   animationEasing: 'cubicInOut',
    //   data: datalist && datalist.length > 0 ? datalist[1] : []
    // },
    // {
    //   name: '经营性收入',
    //   type: 'pictorialBar',
    //   z: 1,
    //   itemStyle: {
    //     normal: {
    //       color: 'transparent',
    //       borderColor: 'rgba(41, 182, 182, 1)',
    //       borderType: 'solid',
    //       borderWidth: 15
    //     }
    //   },
    //   symbol: 'circle',
    //   symbolSize: ['24', '12'],
    //   symbolPosition: 'start',
    //   symbolOffset: [-84, 8],
    //   data: datalist && datalist.length > 0 ? datalist[1] : []
    // },
    // {
    //   name: '经营性收入',
    //   type: 'pictorialBar',
    //   z: 1,
    //   itemStyle: {
    //     normal: {
    //       color: 'transparent',
    //       borderColor: 'rgba(41, 182, 182, 1)',
    //       borderType: 'dashed',
    //       borderWidth: 15
    //     }
    //   },
    //   symbol: 'circle',
    //   symbolSize: ['32', '18'],
    //   symbolPosition: 'start',
    //   symbolOffset: [-84, 11.5],
    //   data: datalist && datalist.length > 0 ? datalist[1] : []
    // }, 
    {
      name: '全区平均',
      data: datalist && datalist.length > 0 ? datalist[2] : [],
      type: 'bar',
      barWidth: 20,
      animationDuration: animationDuration,
      animationEasing: 'cubicInOut',
      itemStyle: {
        normal: {
          label: {
            show: true,
            position: 'top',
            textStyle: {
              color: '#fff',
              fontSize: 14
            }
          },
          borderWidth: 1,
          barBorderRadius: [18, 18, 9, 9],
          color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
            offset: 0,
            color: '#92070D' // 0% 处的颜色
          }, {
            offset: 1,
            color: '#D72A30' // 100% 处的颜色
          }], false)
        }
      }
    }, {
      name: '全区平均',
      type: 'pictorialBar',
      z: 3,
      itemStyle: {
        color: '#EA3C42'
      },
      symbol: 'circle',
      symbolSize: ['20', '10'],
      symbolPosition: 'start',
      symbolOffset: [-28, 0],
      data: datalist && datalist.length > 0 ? datalist[2] : []
    },
    // {
    //   name: '全区平均',
    //   type: 'pictorialBar',
    //   z: 3,
    //   itemStyle: {
    //     color: '#EA3C42'
    //   },
    //   symbol: 'circle',
    //   symbolSize: ['20', '10'],
    //   symbolPosition: 'end',
    //   symbolOffset: [-28, 0],
    //   animationDuration: animationDuration2,
    //   animationEasing: 'cubicInOut',
    //   data: datalist && datalist.length > 0 ? datalist[2] : []
    // },
    // {
    //   name: '全区平均',
    //   type: 'pictorialBar',
    //   z: 1,
    //   itemStyle: {
    //     normal: {
    //       color: 'transparent',
    //       borderColor: 'rgba(240, 52, 58, 1)',
    //       borderType: 'solid',
    //       borderWidth: 15
    //     }
    //   },
    //   symbol: 'circle',
    //   symbolSize: ['24', '12'],
    //   symbolPosition: 'start',
    //   symbolOffset: [-28, 8],
    //   data: datalist && datalist.length > 0 ? datalist[2] : []
    // }, {
    //   name: '全区平均',
    //   type: 'pictorialBar',
    //   z: 1,
    //   itemStyle: {
    //     normal: {
    //       color: 'transparent',
    //       borderColor: 'rgba(240, 52, 58, 1)',
    //       borderType: 'dashed',
    //       borderWidth: 15
    //     }
    //   },
    //   symbol: 'circle',
    //   symbolSize: ['32', '18'],
    //   symbolPosition: 'start',
    //   symbolOffset: [-28, 11.5],
    //   data: datalist && datalist.length > 0 ? datalist[2] : []
    // },
    {
      name: '经常性收入',
      data: datalist && datalist.length > 0 ? datalist[3] : [],
      type: 'bar',
      barWidth: 20,
      animationDuration: animationDuration,
      animationEasing: 'cubicInOut',
      itemStyle: {
        normal: {
          label: {
            show: true,
            position: 'top',
            textStyle: {
              color: '#fff',
              fontSize: 14
            }
          },
          borderWidth: 1,
          barBorderRadius: [18, 18, 9, 9],
          color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
            offset: 0,
            color: '#9F640A' // 0% 处的颜色
          }, {
            offset: 1,
            color: '#DF9421' // 100% 处的颜色
          }], false)
        }
      }
    }, {
      name: '经常性收入',
      type: 'pictorialBar',
      z: 3,
      itemStyle: {
        color: '#DD9830'
      },
      symbol: 'circle',
      symbolSize: ['20', '10'],
      symbolPosition: 'start',
      symbolOffset: [28, 0],
      data: datalist && datalist.length > 0 ? datalist[3] : []
    },
    // {
    //   name: '经常性收入',
    //   type: 'pictorialBar',
    //   z: 3,
    //   itemStyle: {
    //     color: '#DD9830'
    //   },
    //   symbol: 'circle',
    //   symbolSize: ['20', '10'],
    //   symbolPosition: 'end',
    //   symbolOffset: [28, 0],
    //   animationDuration: animationDuration2,
    //   animationEasing: 'cubicInOut',
    //   data: datalist && datalist.length > 0 ? datalist[3] : []
    // },
    // {
    //   name: '经常性收入',
    //   type: 'pictorialBar',
    //   z: 1,
    //   itemStyle: {
    //     normal: {
    //       color: 'transparent',
    //       borderColor: 'rgba(221, 152, 48, 1)',
    //       borderType: 'solid',
    //       borderWidth: 15
    //     }
    //   },
    //   symbol: 'circle',
    //   symbolSize: ['24', '12'],
    //   symbolPosition: 'start',
    //   symbolOffset: [28, 8],
    //   data: datalist && datalist.length > 0 ? datalist[3] : []
    // }, {
    //   name: '经常性收入',
    //   type: 'pictorialBar',
    //   z: 1,
    //   itemStyle: {
    //     normal: {
    //       color: 'transparent',
    //       borderColor: 'rgba(221, 152, 48, 1)',
    //       borderType: 'dashed',
    //       borderWidth: 15
    //     }
    //   },
    //   symbol: 'circle',
    //   symbolSize: ['32', '18'],
    //   symbolPosition: 'start',
    //   symbolOffset: [28, 11.5],
    //   data: datalist && datalist.length > 0 ? datalist[3] : []
    // },
    {
      name: '全区平均',
      data: datalist && datalist.length > 0 ? datalist[4] : [],
      type: 'bar',
      barWidth: 20,
      animationDuration: animationDuration,
      animationEasing: 'cubicInOut',
      itemStyle: {
        normal: {
          label: {
            show: true,
            position: 'top',
            textStyle: {
              color: '#fff',
              fontSize: 14
            }
          },
          borderWidth: 1,
          barBorderRadius: [18, 18, 9, 9],
          color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
            offset: 0,
            color: '#92070D' // 0% 处的颜色
          }, {
            offset: 1,
            color: '#D72A30' // 100% 处的颜色
          }], false)
        }
      }
    },
    // {
    //   name: '全区平均',
    //   type: 'pictorialBar',
    //   z: 3,
    //   itemStyle: {
    //     color: '#EA3C42'
    //   },
    //   symbol: 'circle',
    //   symbolSize: ['20', '10'],
    //   symbolPosition: 'end',
    //   symbolOffset: [84, 0],
    //   animationDuration: animationDuration2,
    //   animationEasing: 'cubicInOut',
    //   data: datalist && datalist.length > 0 ? datalist[4] : []
    // },
    {
      name: '全区平均',
      type: 'pictorialBar',
      z: 3,
      itemStyle: {
        color: '#EA3C42'
      },
      symbol: 'circle',
      symbolSize: ['20', '10'],
      symbolPosition: 'start',
      symbolOffset: [84, 0],
      data: datalist && datalist.length > 0 ? datalist[4] : []
    },
    // {
    //   name: '全区平均',
    //   type: 'pictorialBar',
    //   z: 1,
    //   itemStyle: {
    //     normal: {
    //       color: 'transparent',
    //       borderColor: 'rgba(240, 52, 58, 1)',
    //       borderType: 'solid',
    //       borderWidth: 15
    //     }
    //   },
    //   symbol: 'circle',
    //   symbolSize: ['24', '12'],
    //   symbolPosition: 'start',
    //   symbolOffset: [84, 8],
    //   data: datalist && datalist.length > 0 ? datalist[4] : []
    // }, {
    //   name: '全区平均',
    //   type: 'pictorialBar',
    //   z: 1,
    //   itemStyle: {
    //     normal: {
    //       color: 'transparent',
    //       borderColor: 'rgba(240, 52, 58, 1)',
    //       borderType: 'dashed',
    //       borderWidth: 15
    //     }
    //   },
    //   symbol: 'circle',
    //   symbolSize: ['32', '18'],
    //   symbolPosition: 'start',
    //   symbolOffset: [84, 11.5],
    //   data: datalist && datalist.length > 0 ? datalist[4] : []
    // }
    ]
  },
  // 党组织活动配置对象
  organizationActivities: {
    tooltip: {
      trigger: 'axis',
      axisPointer: {
        type: 'cross',
        label: {
          backgroundColor: '#6a7985'
        }
      }
    },
    legend: {
      icon: 'rect',
      bottom: 15,
      itemWidth: 14,
      itemHeight: 4,
      itemStyle: {
        borderWidth: 1,
        borderColor: '#fff',
        borderType: 'solid'
      },
      textStyle: {
        color: '#fff'
      },
      data: ['活动次数', '党员参与率'],
    },
    grid: {
      top: '15%',
      left: '3%',
      right: '5%',
      bottom: '20%',
      containLabel: true
    },
    xAxis: [
      {
        type: 'category',
        boundaryGap: false,
        axisLine: {
          lineStyle: {
            color: '#fff',
            width: 2
          }
        },
        axisTick: {
          lineStyle: {
            color: '#fff',
            width: 2
          }
        },
        axisLabel: {
          textStyle: {
            color: '#fff'
          },
        },
        data: datalist && datalist.length > 0 ? datalist[2] : []
      }
    ],
    yAxis: [
      {
        type: 'value',
        // name: '活动次数',
        min: 0,
        splitNumber: 4,
        axisLabel: {
          textStyle: {
            color: '#fff'
          }
        }
      }, {
        type: 'value',
        // name: '党员参与率',
        axisLabel: {
          textStyle: {
            color: '#fff'
          }
        }
      }
    ],
    series: [
      {
        name: '党员参与率',
        type: 'line',
        stack: 'Total2',
        smooth: true,
        symbol: 'circle',
        symbolSize: 10,
        yAxisIndex: 1,
        animationDuration: animationDuration,
        animationEasing: 'cubicInOut',
        itemStyle: {
          normal: {
            color: 'rgba(255, 214, 0, 1)'
          }
        },
        lineStyle: {
          color: 'rgba(255, 214, 0, 1)'
        },
        areaStyle: {
          color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
            offset: 0,
            color: 'rgba(38, 103, 159, 1)' // 0% 处的颜色
          }, {
            offset: 1,
            color: 'rgba(38, 103, 159, 0.37)' // 100% 处的颜色
          }], false)
        },
        emphasis: {
          focus: 'series'
        },
        data: datalist && datalist.length > 0 ? datalist[1] : []
      },
      {
        name: '活动次数',
        type: 'line',
        stack: 'Total1',
        smooth: true,
        symbol: 'circle',
        symbolSize: 10,
        yAxisIndex: 0,
        animationDuration: animationDuration,
        animationEasing: 'cubicInOut',
        itemStyle: {
          normal: {
            color: 'rgba(0, 228, 255, 1)'
          }
        },
        lineStyle: {
          color: 'rgba(0, 228, 255, 1)'
        },
        areaStyle: {
          color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
            offset: 0,
            color: 'rgba(0, 228, 255, 1)' // 0% 处的颜色
          }, {
            offset: 1,
            color: 'rgba(0, 228, 255, 0.1)' // 100% 处的颜色
          }], false)
        },
        emphasis: {
          focus: 'series'
        },
        data: datalist && datalist.length > 0 ? datalist[0] : []
      }
    ]
  },
  // 强基指数配置对象
  evaluationScore: {
    // title: datalist,
    color: ['#bb0004', '#FFD48A'],
    tooltip: {
      show: true,
    },
    grid: {
      left: '10%',
      top: "19%",
      bottom: "15%",
    },
    xAxis: {
      show: false,
      data: [
        '一季度',
        '二季度',
        '三季度',
        '四季度'
      ],
      axisTick: {
        show: false
      },
      axisLabel: {
        color: '#5EA2ED',
        interval: 0
      },
      axisLine: {
        lineStyle: {
          color: '#1B5BBA',
        }
      }
    },
    yAxis: {
      show: false,
      splitLine: { show: false },
      axisLine: {
        lineStyle: {
          color: '#1B5BBA',
        }
      },
      axisLabel: {
        color: '#5EA2ED',
        interval: 0
      }
    },
    animationEasing: 'elasticOut',
    series: [{
      type: 'pictorialBar',
      coordinateSystem: 'cartesian2d',
      data: seriesData
    }]
  }
})